<?php
require_once '../includes/include_dao.php';
if ($_POST['submit-action'] == 'form_insert') :
	//print_r($_REQUEST);
	$template = new Template(); 
	$template->title = $_POST['title']; 
	$template->document = $_POST['document']; 
	$template->updated = date('Y-m-d H:i:s'); 
	DAOFactory::getTemplateDAO()->insert($template);
	
	$url = '/template.php?template=' . $template->template;
	//print $url;
	header(sprintf('Location: %s', $url));
	 
endif;

$path_form = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) :
	$path_form .= '?' . htmlentities($_SERVER['QUERY_STRING']);
endif;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Template</title>
<link href="../includes/css/screen.css" type="text/css" rel="stylesheet" media="screen,projection" />
<style>
.file_input_textbox
{
	float: left
}

.file_input_div
{
	position: relative; 
	width: 100px; 
	height: 23px; 
	overflow: hidden;
}
.file_input_button
{
	position: absolute; 
	top: 0px;
}
.button-red{
	width:100px;
	color:#FFFFFF;
	background: #b41818;
	border: solid 1px #E5E5E5;
	-moz-border-radius: 5px;
	outline: 0;
	padding: 1px;
	-webkit-border-radius: 5px;
}

.file_input_hidden
{
	font-size: 45px; 
	position: absolute; 
	right: 0px; 
	top: 0px; 
	opacity: 0; 
	
	filter: alpha(opacity=0); 
	-ms-filter: "alpha(opacity=0)"; 
	-khtml-opacity: 0; 
	-moz-opacity: 0;
}
</style>
</head>
<body>
<div id="layout">
  <div id="header">
    <h1 id="logo"><a href="/" title="Access the HOME page">sparked<span> </span></a></h1>
    <hr class="noscreen" />
    <div id="navigation">
      <ul>
        <li><a href="/" title="HOME">HOME</a></li>
        <li><a href="/templates.php" title="TEMPLATES">TEMPLATES</a></li>
        <li><a href="/tags.php" title="TAGS">TAGS</a></li>
      </ul>
    </div>
    <hr class="noscreen" />
  </div>
  <div class="banner-box">
    <div class="banner-box-content">
      <div class="content">
        <h2>Add Template</h2>
        <p>Create a new kickstart template by hand or upload an existing file.</p>
        <p>Use the controls to Upload an existing kickstart file from your computer. This file can be used as is, or customized prior to saving. </p>
      </div>
      <div id="box-right">
        <div id="box-right-content">
          <form action="<?php echo $path_form; ?>" method="post" enctype="multipart/form-data">
            <p><span>Browse to a kickstart file located on your local machine.</span><br />
              <input type="text" id="temp_input" class="file_input_textbox" readonly="readonly" />
            </p>
            <div class="file_input_div">
              <input type="button" value="Browse" class="file_input_button button-red" />
              <input name="kickstart" type="file" class="file_input_hidden" onchange="javascript: document.getElementById('temp_input').value = this.value" />
            </div>
            <p>
              <input name="Submit" type="submit" value="Upload" class="button-red" />
            </p>
            <p></p>
          </form>
        </div>
      </div>
    </div>
    <div class="banner-bottom"></div>
  </div>
  <div id="main">
    <h2>Add Template</h2>
    <form action="<?php echo $path_form; ?>" method="post" name="form_insert" id="form_insert">
      <h3>Title</h3>
      <input name="title" type="text" id="title" value="" size="32" />
      <h3>Template Document</h3>
      <textarea name="document" cols="75" rows="30" wrap="virtual"><?php if (isset($_FILES['kickstart']) && !$_FILES['kickstart']['error']) : 
	  																	include $_FILES['kickstart']['tmp_name'] ;
																	endif;?>
</textarea>
      <p>
        <input type="hidden" name="submit-action" value="form_insert" />
        <input name="submit" type="submit" value="Save" class="button-big" />
        <input type="reset" name="reset" value="Reset" class="button-big" />
      </p>
    </form>
  </div>
</div>
<div id="footer">
  <div id="footer-inside">
    <p id="copyright"><a href="http://code.google.com/p/sparked/" title="View Google Code Project" target="_blank">&copy;<?php echo date('Y'); ?> All Rights Reserved.</a></p>
  </div>
  <div style="clear: both;"></div>
</div>
</body>
</html>
